<html>
<#include "../common/header.ftl">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

<body>
<div id="wrapper" class="toggled">

<#--边栏sidebar-->
    <#include "../common/nav.ftl">

<#--主要内容content-->
    <div id="page-content-wrapper">
        <div class="container-fluid">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <form role="form" method="post" action="/sell/seller/product/save">
                        <div class="form-group">
                            <label>名称</label>
                            <input name="productName" class="form-control" type="text" value="${(productInfo.productName)!''}"/>
                        </div>
                        <div class="form-group">
                            <label>价格</label>
                            <input name="productPrice" type="text" class="form-control" value="${(productInfo.productPrice)!''}"/>
                        </div>
                        <div class="form-group">
                            <label>库存</label>
                            <input name="productStock" type="number" class="form-control" value="${(productInfo.productStock)!''}"/>
                        </div>
                        <div class="form-group">
                            <label>描述</label>
                            <input name="productDescription" type="text" class="form-control" value="${(productInfo.productDescription)!''}">
                        </div>
                        <div class="form-group">
                            <label>图片</label>
                            <img height="100" width="100" src="${(productInfo.productIcon)!''}" alt="">
                            <input id = "myid" name="productIcon" type="text" class="form-control" value="${(productInfo.productIcon)!''}"/>
                        </div>
                        <div class="form-group">
                            <label>类目</label>
                            <select name="categoryType" class="form-control">
                                <#list categoryList as category>
                                    <option value="${(category.categoryType)}"
                                            <#if (productInfo.categoryType)?? && productInfo.categoryType==category.categoryType>
                                                selected
                                            </#if>>
                                        ${category.categoryName}
                                    </option>
                                </#list>

                            </select>
                        </div>
                        <input hidden type="text" name="productId" value="${(productInfo.productId)!''}">

                        <button type="submit" class="btn btn-default">提交</button>
                    </form>
                    <input id="productIcon1" type="file" accept=".jpg, .png">上传图片</input>
                </div>
            </div>
        </div>
    </div>

</div>
</body>
<script lang="js">
    const fileUploader = document.getElementById('productIcon1');

    var xwa = document.getElementById(`myid`);


    fileUploader.addEventListener('change', (event) => {
        const files = event.target.files;
        const formData = new FormData();
        console.log('files', files);
        formData.append("file", files[0]);
        axios({
            method: 'post',
            headers: {
                "Content-Type": "multipart/form-data",
            },
            url: '/sell/upload/image',
            data: formData
        }).then(function (response) {
                console.log(response.data);
            xwa.setAttribute("value",response.data)
            })
            .catch(function (error) {
                console.log(error);
            });
    });



    if( document.cookie.indexOf("as") == -1){
            window.location = '/sell/seller/user/login'
    }
    console.log( document.cookie.indexOf("asa"))
</script>
</html>